#ifndef RINGBUF_H_
#define RINGBUF_H_

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct RingBuf_Object {
    uint8_t *buf;          // 外部提供的缓冲区
    size_t   size;         // 缓冲区总大小
    volatile size_t head;  // 写指针
    volatile size_t tail;  // 读指针
    size_t   max;          // 统计峰值（可选）
} RingBuf_Object;

typedef RingBuf_Object* RingBuf_Handle;

void RingBuf_construct(RingBuf_Handle obj, unsigned char *bufPtr, size_t bufSize);
int  RingBuf_put(RingBuf_Handle obj, unsigned char data);
int  RingBuf_get(RingBuf_Handle obj, unsigned char *data);
int  RingBuf_peek(RingBuf_Handle obj, unsigned char *data); 
int  RingBuf_getCount(RingBuf_Handle obj);
int  RingBuf_getMaxCount(RingBuf_Handle obj);
bool RingBuf_isFull(RingBuf_Handle obj);

#ifdef __cplusplus
}
#endif
#endif
